const Minio = require('minio');

const minioClient = new Minio.Client({
  endPoint: process.env.MO_HOST,  // 替换为你的 MinIO 地址
  port: process.env.MO_PORT,
  useSSL: false,
  accessKey: process.env.MO_ACCESS_KEY,
  secretKey: process.env.MO_SECRET_KEY
});

const bucketName = process.env.MO_BUCKET_NAME;

// 确保存储桶存在
(async () => {
  try {
    const exists = await minioClient.bucketExists(bucketName);
    if (!exists) {
      await minioClient.makeBucket(bucketName);
    }
  } catch (error) {
    console.error('MinIO 初始化失败:', error);
  }
})();

module.exports = { minioClient, bucketName };